<?php
class site_k_category extends ss_konstrukt_master_component {
	protected $templates;
	protected $structureMapper;
	protected $entryMapper;
	protected $strucure;
	protected $node;
	protected $entries;
	protected $entry;
	
	public function __construct($ss_settings, site_templatefactory $templates, site_dao_structure_mapper $structureMapper, site_dao_entry_mapper $entryMapper){
		$this->structureMapper=$structureMapper;
		$this->entryMapper=$entryMapper;
		$this->structure=$structureMapper->master();
    	$this->templates = $templates;
		$this->settings=$ss_settings;
	}
	
	public function dispatch(){
		//$this->node=$this->structure->getNodeFromSlug($this->name());
		//$this->document->setTitle("Structure ".$this->node->headline());
		ss_error::log('Category entries dispatch '.$this->name());
		$this->entries=$this->entryMapper->getEntriesByCategorySlug($this->name());
		//ss_error::log($this->entries,'Entries for '.$this->name());
		return parent::dispatch();
	}
	
	protected function map($name){
		ss_error::log('Category map '.$name);
		$this->entry=$this->entryMapper->getEntryBySlug($name)->clean();
		if($this->entry)return 'site_k_entry';
	}
	
	public function entry(){
		return $this->entry;
	}
	
	public function GET(){
		ss_error::log('Category GET');
		$this->content=array();
		foreach($this->entries as $obj){
			$this->content[]=$obj->detail();
		}
		return parent::GET();
	}
	
	protected function renderHtml() {
    	$smarty = $this->templates->create();
	    $smarty->assign('content', $this->content);
		$smarty->register_object('ss_path', $this->settings->server->appath);
	    $smarty->assign('context', $this);
    	return $smarty->fetch("master.tpl");
	}
}
?>